package netty.chat.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import netty.chat.protocal.ProtocalMsg;
import netty.chat.utils.ObjectUtils;

import java.util.List;

/**
 * ��byte����decodeת���ɶ���
 */
public class BinaryMsgDecoder extends ByteToMessageDecoder{

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
       // System.out.println("BinaryMsgDecoder decode");

        byte[] bytes = new byte[in.readableBytes()];
        in.readBytes(bytes);
        ProtocalMsg msg = (ProtocalMsg)ObjectUtils.toObject(bytes);
        out.add(msg);
    }

}
